package com.imooc.beanannotation.jsr;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.stereotype.Service;

//@Service
@Named  //与@Component 等效
public class JsrServie {
	
	//@Resource   //方法1  等价于@Autowired
	//@Inject
	private JsrDAO jsrDAO;
	
	//@Resource   //方法2  等价于@Autowired
	@Inject
	public void setJsrDAO(@Named("jsrDAO") JsrDAO jsrDAO) { //@Named("jsrDAO")指定名称为jsrDAO对应的那个实现类，见于多个实现类的情况，类似于@Qualifier
		this.jsrDAO = jsrDAO;
	}
	
	@PostConstruct
	public void init() {
		System.out.println("JsrServie init.");
	}
	
	@PreDestroy
	public void destroy() {
		System.out.println("JsrServie destroy.");
	}

	public void save() {
		jsrDAO.save();
	}
	
}
